import request from '@/utils/request'

import qs from 'qs'
import cookies from 'vue-cookies'

/**
 * 登陆用户
 * @param data
 */
export function login(data, code) {
  let captcha = { captcha_key: cookies.get('captcha_key'), captcha_code : code }
  return request({
    url: '/login?' + qs.stringify(captcha),
    method: 'post',
    data: JSON.stringify(data)
  })
}

/**
 * 获取图片验证码
 */
export function captcha() {
  return request({
    url: '/captcha',
    method: 'get'
  })
}

/**
 * 注册用户
 * @param data
 */
export function regster(data) {
  return request({
    url: '/register',
    method: 'post',
    data: JSON.stringify(data)
  })
}

/**
 * 发送邮箱验证码
 * @param email
 */
export function sendMailCode(email) {
  return request({
    url: '/register/code?email=' + email,
    method: 'get'
  })
}

/**
 * 退出登录
 */
export function logout() {
  return request({
    url: '/_logout',
    method: 'get'
  })
}
